package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.Notification;
import com.example.haoqisystem.request.SendEmailToStudentRequest;
import com.example.haoqisystem.request.CreateWebNoticeRequest;
import com.example.haoqisystem.request.UpdateWebNoticeRequest;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.service.NotificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor(onConstructor_ ={@Autowired} )
@Api(tags = "通知Api")
@RequestMapping("/notification")
public class NotificationController {

    private final NotificationService notificationService;

    @ApiOperation(value = "给学员发送邮件通知")
    @PostMapping("/sendEmail")
    public BaseResponse<String> sendEmail(@RequestBody SendEmailToStudentRequest request){
        return notificationService.sendEmailToStudent(request);
    }

    @ApiOperation(value = "添加网站通知")
    @PostMapping("/addWebNotice")
    public BaseResponse<Notification> addWebNotice(@RequestBody CreateWebNoticeRequest request){
        return notificationService.sendWebNotification(request);
    }

    @ApiOperation(value = "修改网站通知")
    @PutMapping("/update")
    public BaseResponse<Notification> update(@RequestBody UpdateWebNoticeRequest request){
        return notificationService.updateWebNotice(request);
    }

    @ApiOperation(value = "删除网站通知")
    @GetMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "通知id",required = true)
    })
    public BaseResponse<String> delete(Long id){
        return notificationService.delete(id);
    }

    @ApiOperation(value = "查询通知列表")
    @GetMapping("/queryList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lectureName",value = "课程名（模糊查询）"),
            @ApiImplicitParam(name = "betweenTime",value = "开课时间(yyyy-MM-dd 至 yyyy-MM-dd)"),
            @ApiImplicitParam(name = "lecturePlace",value = "开课地点（模糊查询）")
    })
    public BaseResponse<List<Notification>> queryList(String lectureName,String betweenTime,String lecturePlace){
        return notificationService.queryList(lectureName,betweenTime,lecturePlace);
    }

}
